package com.example.gisdata.controller;

import com.example.gisdata.domain.PageResult;
import com.example.gisdata.domain.Result;
import com.example.gisdata.service.IQueryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/get/line")
@Slf4j
public class QueryController {
    @Resource
    IQueryService queryService;
    @GetMapping(value = "/getData")
    public List<Map<String, Object>> getData(@RequestParam(name="coorX",required=true) BigDecimal coorX,@RequestParam(name="coorY",required=true) BigDecimal coorY ) {
        return queryService.getDataList(coorX,coorY);
    }
    @GetMapping(value = "/getPage")
    public Result<PageResult<Map<String, Object>>> getPage(@RequestParam("pageSize") Integer pageSize,
                                        @RequestParam("pageNum") Integer pageNumber){
        PageHelper.startPage(pageSize, pageNumber);
        List<Map<String, Object>> dataList=queryService.getPage();
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(dataList);
        PageResult<Map<String, Object>> pageResult = new PageResult<>(
                pageInfo.getList(), // 当前页的数据列表
                pageInfo.getTotal(), // 总记录数
                pageInfo.getPageNum(), // 当前页码
                pageInfo.getPageSize(), // 每页大小
                pageInfo.getPages() // 总页数
        );
        return Result.success(pageResult);
    }
}
